import Vue from "vue"
import App from "./App.vue"
import router from "./router"
import store from "./store"
import iView from 'iview'
import 'iview/dist/styles/iview.css'
Vue.use(iView)
import 'element-ui/lib/theme-chalk/index.css'
import { DatePicker } from 'element-ui'
Vue.use(DatePicker)

Vue.config.productionTip = false

Vue.prototype.$qs = params => require('qs').stringify(params)

router.beforeEach((to, from, next) => {
    if (to.meta.requireAuth) {
        if (window.localStorage.getItem('token')) {
            store.dispatch('Index').then((res) => {
                if (res.status === 200) {
                    next()
                }
            })
        } else {
            next({
                path: '/login',
                query: {redirect: to.fullPath}
            })
        }
    }
    else {
        next()
    }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app")
